import java.util.ArrayDeque;
import java.util.Deque;

public class Solution02 {
	public boolean findTarget(TreeNode root, int k) {
		// 创建哈希表，存储已经遍历过的节点
		Set<Integer> set = new HashSet<>();
		Deque<TreeNode> stack = new ArrayDeque<>();
		TreeNode curNode = root;
		while (curNode != null || !stack.isEmpty()) {
			while (curNode != null) {
				stack.addLast(curNode);
				curNode = curNode.left;
			}
			curNode = stack.pollLast();
			// 查找是否匹配
			if (set.contains(k - curNode.val)) {
				return true;
			}
			set.add(curNode.val);
			curNode = curNode.right;
		}
		return false;
	}
}
